from datetime import datetime

from sqlalchemy import Boolean, Column, ForeignKey, Integer, String, DateTime, Float, Date, TIMESTAMP, func, Enum
from sqlalchemy.orm import relationship

from database import Base


class Course(Base):
    __tablename__ = "course"

    course_id = Column(Integer, primary_key=True, autoincrement=True, comment="课程ID：课程的唯一标识符。自动递增。")
    course_name = Column(String(100), nullable=False, comment="课程名称：课程的名称。")
    course_code = Column(String(20), nullable=False, comment="课程代码：课程的唯一代码。")
    teacher_id = Column(Integer, ForeignKey("teacher.teacher_id"), comment="教师ID：授课教师的ID。")
    credit = Column(Float, nullable=True, comment="学分：课程的学分。")
    department = Column(String(100), nullable=True, comment="开设院系：课程所属的开设院系。")
    description = Column(String(500), nullable=True, comment="课程描述：课程的详细描述。")
    max_num = Column(Integer, nullable=True, comment="可选人数：课程的最大可选人数。")
    num = Column(Integer, default=0, comment="已选人数")
    create_time = Column(DateTime, nullable=True, default=datetime.utcnow, comment="创建时间")
    status = Column(Integer, nullable=True, default=1, comment="状态（1可选，0不可选）")
    update_time = Column(DateTime, nullable=True, onupdate=datetime.utcnow, comment="更新时间")
    semester_id = Column(Integer, ForeignKey("semester.id"), nullable=True, comment="学期id")

    teacher = relationship("Teacher")
    semester = relationship("Semester")

class Semester(Base):
    __tablename__ = "semester"

    id = Column(Integer, primary_key=True, autoincrement=True)
    name = Column(String(50), nullable=False)
    start_time = Column(Date, nullable=False, comment="开学日期")
    week_num = Column(Integer, nullable=False, comment="周数")
    create_time = Column(TIMESTAMP, nullable=True, server_default=func.current_timestamp())


class Teacher(Base):
    __tablename__ = "teacher"

    teacher_id = Column(Integer, primary_key=True, autoincrement=True, comment="教师ID：教师的唯一标识符。自动递增。")
    name = Column(String(50), nullable=False, comment="姓名：教师的姓名。")
    gender = Column(Enum('male', 'female', name='gender_enum'), nullable=False, comment="性别：教师的性别。可选值为\"male\"（男性）或\"female\"（女性）")
    birthday = Column(Date, nullable=True, comment="出生日期：教师的出生日期。")
    department = Column(String(50), nullable=True, comment="学院：教师所属的学院。")
    title = Column(String(50), nullable=True, comment="职称：教师的职称。")
    phone = Column(String(200), nullable=True, comment="联系方式：教师的联系方式。")
    address = Column(String(200), nullable=True, comment="地址")
    create_time = Column(DateTime, nullable=True, server_default=func.current_timestamp(), comment="创建时间")
    id_card = Column(String(20), nullable=True, comment="身份证")